<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>基础库管理安保工程项目</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/autocomplete/jquery.autocomplete.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-form.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/uploader/swfobject.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/uploader/jquery.uploadify.v2.1.4.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/autocomplete/jquery.autocomplete.js" ></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/util/jquery.cookie.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/YMLib.js"></script>
<%--<script type="text/javascript" src="${pageContext.request.contextPath}/page/qqgl/js/loadTJ.js"></script>--%>
<%--<script type="text/javascript" src="${pageContext.request.contextPath}/page/qqgl/kxxyj/js/kxxyj.js"></script>--%>

<style type="text/css">
TD {
font-size: 12px;
} 
a{
text-decoration:none;
}
</style>
</head>
<body>
<script type="text/javascript">
	$(function(){
		fileShow(parent.obj.id,"cgsjhwj");
		loadFileUpload();
	});

	function loadFileUpload(){
		$("#uploadGkpf").uploadify({
			/*注意前面需要书写path的代码*/
			'uploader' : '../../../js/uploader/uploadify.swf',
			'script' : '/jxcsxm/tjbb/uploadGkpf.do',
			'cancelImg' : '../../../js/uploader/cancel.png',
			'queueID' : 'fileQueue',
			'fileDataName' : 'uploadGkpf',
			'auto' : false,
			'multi' : false,
			'buttonImg': '../../../js/uploader/bdll.png',
			'simUploadLimit' : 3,
			'sizeLimit' : 524288000,
			'queueSizeLimit' : 5,
			'fileDesc' : '支持格式:doc，docx，pdf，rar，zip',
			'fileExt' : '*.doc;*.docx;*.pdf;*.rar;*.zip;',
			'height' : 30,
			'width' : 92,
			'scriptData' : {
				'xmjbxx.xmbm':parent.obj.id,
				'xmjbxx.filetype':'cgsjhwj',
			},
			onComplete : function(event, queueID, fileObj, response, data) {
				alert(response);
				fileShow(parent.obj.id,"cgsjhwj");
			},
			onError : function(event, queueID, fileObj) {
				alert("文件:" + fileObj.name + "上传失败");
			},
			onCancel : function(event, queueID, fileObj) {
			},
			onQueueFull : function(event, queueSizeLimit) {
				alert("最多支持上传文件数为：" + queueSizeLimit);
			}
		});
	}
	function upload(){		
/* 			$("#uploadGkpf").uploadifySettings('scriptData',{'kxxyj.xmbm':parent.YMLib.Var.xmbm,'kxxyj.gkpfwh':$('#gkpfwh').val()});
 */			$('#uploadGkpf').uploadifyUpload();
	
	}

	function fileShow(xmbm,type){
		$.ajax({
			type:'post',
//		url:'/jxzhpt/qqgl/queryFileByXmbm.do',
//		data:'file.parentid='+xmbm+'&file.filetype='+type,
//		dataType:'json',
			url:'/jxcsxm/tjbb/queryFjByParentId.do',
			dataType:'json',
			data:'uploads.id='+xmbm,
			success:function(data){
				$("#gkpfTable").empty();
				for ( var i = 0; i < data.length; i++) {
					if(data[i].filetype==type){
						var tr = "<tr><td style='background-color: #ffffff; height: 25px;' align='left'> " + data[i].filename + "</td><td style='background-color: #ffffff; height: 25px;' align='left'>" +
								'  <a href="javascript:downFile('+"'"+data[i].fileurl.replace(/\\/g,"%2F")+"',"+"'"+data[i].filename+"'"+')" style="text-decoration:none;color:#3399CC;">下载</a>  |  ' +
								"<a href='javascript:void(0)'style='text-decoration:none;color:#3399CC; ' onclick=deleteFile('"+data[i].fid+"')>删除</a></td></tr>";
						$("#gkpfTable").append(tr);
					}
				}
			}
		});
	}
	/**
	 * 下载文件
	 * @param id 文件ID
	 */
	function downFile(fileurl,filename){
		parent.window.location.href="/jxcsxm/tjbb/downAbgcFile.do?uploads.fileurl="+encodeURI(encodeURI(fileurl))+"&uploads.filename="+encodeURI(encodeURI(filename));
	}
	/**
	 * 删除文件
	 * @param id 文件ID
	 */
	function deleteFile(id){
		if(confirm('确定删除所选文件？')){
			$.ajax({
				type : "POST",
				url : "/jxcsxm/tjbb/deleteFile.do",
				dataType : 'json',
				data : 'uploads.fid=' +id,
				success : function(msg){
					if(msg){
						alert('删除成功！');
						fileShow(parent.obj.id,'cgsjhwj');
					}else{
						YMLib.Tools.Show('删除失败,请选择要删除的文件！',3000);
					}
				},
				error : function(){
					YMLib.Tools.Show('服务器请求无响应！error code = 404',3000);
				}
			});
		}
	}
</script>
<form action="" id="kxxyj">
<table style="width: 100%; background-color: #aacbf8; font-size: 12px" border="0" cellpadding="3" cellspacing="1">
			<tr style="height: 15px;">
				<td style="background-color: #ffffff; height: 20px;width:18%" align="left" colspan="5">
					<table style="margin-top:5px;background-color: #aacbf8; font-size: 12px" border="0" cellpadding="1" cellspacing="1">
							<tbody id="gkpfTable"></tbody>
						</table>
						<table>
							<tr>
								<td><input type="file" value="选择批复文件" style="background-image: url('../../../js/uploader/bdll.png');" name="uploadGkpf" id="uploadGkpf" /></td>
								<td><div id="fileQueue" ></div></td>
							</tr>
						</table>
				</td>
			</tr>
			<tr style="height: 35px;">
				<td colspan="6" style="background-color: #ffffff;"align="center">
				<a href="javascript:void(0)" name="uploadFile" id="uploadFile" class="easyui-linkbutton" iconCls="upload"  onclick="upload()"  style="border-width:0px;cursor: hand;" >上传</a>
			</tr>
		</table>
	</form>
</body>
</html>